package com.atguigu.jxc.controller;

import com.alibaba.fastjson.JSONArray;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.OverflowList;
import com.atguigu.jxc.entity.OverflowListGoods;
import com.atguigu.jxc.service.OverflowListGoodsService;
import com.atguigu.jxc.util.UserUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author tongatong
 * @name OverflowListGoodsController
 * @description
 * @date 2021/10/15
 * @time 23:09
 */
@RestController
@RequestMapping("/overflowListGoods")
public class OverflowListGoodsController {
    @Resource
    private OverflowListGoodsService overflowListGoodsService;

    @PostMapping("/save")
    public ServiceVO<Void> save(OverflowList overflowList,
                                String overflowListGoodsStr,
                                String overflowNumber,
                                HttpSession session) {
        overflowList = UserUtil.setUserInfoForObject(session, overflowList);
        System.out.println(overflowList);
        List<OverflowListGoods> overflowListGoodsList = JSONArray.parseArray(overflowListGoodsStr, OverflowListGoods.class);
        overflowListGoodsService.save(overflowList, overflowListGoodsList, overflowNumber);

        return new ServiceVO<>(SuccessCode.SUCCESS_CODE, SuccessCode.SUCCESS_MESS);
    }
}
